package com.lianda.mutiple.pattern.aobj.example;

import com.lianda.mutiple.pattern.future.Future;
import com.lianda.mutiple.pattern.future.FutureService;

import java.util.concurrent.TimeUnit;

//订单Service实现
public class OrderServiceImpl implements OrderService {


    @Override
    public Future<String> findOrderDetails(long orderId) {
        //借用future

        return FutureService.<Long, String>newService().submit(input -> {
            try {
                TimeUnit.SECONDS.sleep(10);
                System.out.println("process the orderID->" + orderId);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            return "The order Details Information";
        }, orderId, null);
    }

    @Override
    public void order(String account, long orderId) {
        try {
            TimeUnit.SECONDS.sleep(10);
            System.out.println("process the order for account" + account + ",orderId " + orderId);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
